<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加图书</title>
    <link rel="stylesheet" href="/static/css/hui.css">
    </style>
</head>

<body>


    <header class="hui-header">
        <div id="hui-back"></div>
        <h1>管理员添加书本&nbsp;&nbsp;&nbsp;&nbsp;</h1>
    </header>
    <div class="hui-wrap">
        <form id="form1" class="hui-form" style="padding:28px 10px;" enctype="multipart/form-data">
            <div class="hui-form-items">
                <div class="hui-form-items-title">图书编号</div>
                <input type="tel" class="hui-input" placeholder="图书编号" id="bookID">
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">书名</div>
                <input type="tel" class="hui-input" placeholder="书名" id="bookName">
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">作者</div>
                <input type="tel" class="hui-input" placeholder="作者" id="author">
            </div>
            <div class="hui-form-items">
                <div class="hui-form-items-title">出版社</div>
                <input type="tel" class="hui-input" placeholder="出版社" id="publishing">
            </div>

            <button type="button" class="hui-button hui-button-large hui-primary" id="addBook" style="margin-top:15px;">提交</button>

        </form>

    </div>

    <script src="/static/js/hui.js"></script>

    <script>
        hui('#addBook').click(() => {
            var bookID = hui('#bookID').val();
            var bookName = hui('#bookName').val();
            var author = hui('#author').val();
            var publishing = hui('#publishing').val();

            if (bookID && bookName && author && publishing) {
                hui.postJSON(
                    'http://127.0.0.1:5000/addBook/',
                    { bookID: bookID, bookName: bookName, author: author, publishing: publishing },
                    function (res) {
                        if (res.code == 1) {
                            window.location.href = 'http://127.0.0.1:5000/admin/'
                        } else {
                            hui.toast(res.message);
                        }
                    },
                    function (e) {
                        hui.iconToast('读取消息失败', 'warn');
                    }
                );
            } else {
                hui.toast('请填写完整');
            }
        })
    </script>

</body>

</html>